package com.jmpt.fangbohui.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.utils.DebugLog;
import com.jmpt.fangbohui.utils.ImageLoaderHelper;


/**
 * A simple {@link android.support.v4.app.Fragment} subclass.
 */
public class HomeBannerFragment extends Fragment {
    public static final int MODE_FIT_XY = 1;
    public static final int MODE_CENTER = 2;
    public int mode = MODE_FIT_XY;

    ImageView.ScaleType mScaleType = ImageView.ScaleType.FIT_XY;

    public HomeBannerFragment() {
        // Required empty public constructor
    }

    public static HomeBannerFragment create(String imgUri) {
        HomeBannerFragment fragment = new HomeBannerFragment();
        Bundle bundle = new Bundle();
        bundle.putString("imgUri", imgUri);
        fragment.setArguments(bundle);
        return fragment;
    }

    public static HomeBannerFragment createHouseDetail(String imgUri) {
        HomeBannerFragment fragment = new HomeBannerFragment();
        Bundle bundle = new Bundle();
        bundle.putString("imgUri", imgUri);
        bundle.putInt("mode", MODE_CENTER);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home_banner, container, false);
        ImageView mPhoto = (ImageView) rootView.findViewById(R.id.photo);
        String imgUri = getArguments().getString("imgUri");
        DebugLog.i("imgUri" + imgUri);
        ImageLoaderHelper.displayImage(imgUri, mPhoto);
        if (getArguments().containsKey("mode")) {
            mode = getArguments().getInt("mode");
            if (mode == MODE_CENTER) {
                mPhoto.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            }
        }
        return rootView;
    }
}
